/*
  卷轴抽奖机
  梧桐
 */
var status = -1;
var itemList = Array(     
			Array(2040012,500,1,0),//头盔智力卷轴 诅咒~30%
		    Array(2040013,500,1,0),//头盔智力卷轴 诅咒70%
			Array(2040014,500,1,0),//头盔命中率诅咒卷轴70%
			Array(2040015,500,1,0),//头盔命中率诅咒卷轴30%
			Array(2040016,500,1,0),//头盔命中率卷轴10%
			Array(2040017,500,1,0),//头盔命中率卷轴60%
			Array(2040025,500,1,0),//头盔智力卷轴 60%
			Array(2040026,500,1,0),//头盔智力卷轴 10%
			Array(2040028,500,1,0),//头盔敏捷卷轴 70%
			Array(2040029,500,1,0),//头盔敏捷卷轴 60%
			Array(2040030,500,1,0),//头盔敏捷卷轴 30%
			Array(2040031,500,1,0),//头盔敏捷卷轴 10%
			Array(2040105,500,1,0),//脸部装饰回避率卷轴10%
			Array(2040106,500,1,0),//脸部装饰回避率卷轴 60%
			Array(2040108,500,1,0),//脸部装饰回避率卷轴 30%
			Array(2040109,500,1,0),//脸部装饰回避率卷轴 70%
			Array(2040200,500,1,0),//眼部装饰命中率卷轴10%
			Array(2040201,500,1,0),//眼部装饰命中率卷轴 60%
			Array(2040203,500,1,0),//眼部装饰命中率卷轴 30%
			Array(2040204,500,1,0),//眼部装饰命中率卷轴 70%
			Array(2040205,500,1,0),//眼部装饰智力卷轴10%
			Array(2040206,500,1,0),//眼部装饰智力卷轴 60%
			Array(2040208,500,1,0),//眼部装饰智力卷轴 30%
			Array(2040209,500,1,0),//眼部装饰智力卷轴 70%
			Array(2040301,500,1,0),//耳环智力卷轴 60% 
			Array(2040302,500,1,0),//耳环智力卷轴 10% 
			Array(2040304,500,1,0),//耳环智力卷轴 70%
			Array(2040305,500,1,0),//耳环智力卷轴 30%
			Array(2040306,500,1,0),//耳环敏捷卷轴 70%
			Array(2040307,500,1,0),//耳环敏捷卷轴 30%
			Array(2040316,500,1,0),//耳环敏捷卷轴 100%
			Array(2040317,500,1,0),//耳环敏捷卷轴 60%
			Array(2040318,500,1,0),//耳环敏捷卷轴 10%
			Array(2040320,500,1,0),//耳环装饰运气卷轴 70%
			Array(2040321,500,1,0),//耳环装饰运气卷轴 60%
			Array(2040322,500,1,0),//耳环装饰运气卷轴 30%
			Array(2040323,500,1,0),//耳环装饰运气卷轴 10%
			Array(2040406,500,1,0),//上衣力量卷轴 70%
			Array(2040407,500,1,0),//上衣力量卷轴 30%
			Array(2040410,500,1,0),//上衣运气诅咒卷轴 70%
			Array(2040411,500,1,0),//上衣运气诅咒卷轴 30%
			Array(2040412,500,1,0),//上衣运气 10%
			Array(2040413,500,1,0),//上衣运气 60%
			Array(2040501,500,1,0),//全身铠甲敏捷卷轴 60%
			Array(2040502,500,1,0),//全身铠甲敏捷卷轴 10%
			Array(2040508,500,1,0),//全身铠甲敏捷卷轴 70%
			Array(2040509,500,1,0),//全身铠甲敏捷卷轴30%
			Array(2040513,500,1,0),//全身铠甲智力卷轴 60%
			Array(2040514,500,1,0),//全身铠甲智力卷轴 10%
			Array(2040515,500,1,0),//全身铠甲运气卷轴 100%
			Array(2040516,500,1,0),//全身铠甲运气卷轴 60%
			Array(2040517,500,1,0),//全身铠甲运气卷轴 10%
			Array(2040518,500,1,0),//全身盔甲智力卷轴 70%
			Array(2040519,500,1,0),//全身盔甲智力卷轴 30%
			Array(2040520,500,1,0),//全身盔甲幸运卷轴 70%
			Array(2040521,500,1,0),//全身盔甲幸运卷轴 30%
			Array(2040531,500,1,0),//全身盔甲力量 70%
			Array(2040532,500,1,0),//全身盔甲力量 60%
			Array(2040533,500,1,0),//全身盔甲力量 30%
			Array(2040534,500,1,0),//全身盔甲力量 10%
			Array(2040610,500,1,0),//裤裙敏捷卷轴 70%
			Array(2040611,500,1,0),//裤裙敏捷卷轴 30%
			Array(2040612,500,1,0),//裤裙敏捷卷轴 10%
			Array(2040613,500,1,0),//裤裙敏捷卷轴 60%
			Array(2040614,500,1,0),//裤裙敏捷卷轴 100%
			Array(2040701,500,1,0),//鞋子敏捷度卷轴60%
			Array(2040702,500,1,0),//鞋子敏捷度卷轴 10%
			Array(2040714,500,1,0),//鞋子跳跃诅咒卷轴 70%
			Array(2040715,500,1,0),//鞋子跳跃诅咒卷轴 30%
			Array(2040800,500,1,0),//手套敏捷卷轴 100%
			Array(2040801,500,1,0),//手套敏捷卷轴 60%
			Array(2040802,500,1,0),//手套敏捷卷轴 10%
			Array(2040803,200,1,1),//手套攻击卷轴 100%
			Array(2040804,200,1,1),//手套攻击卷轴 60%
			Array(2040805,200,1,1),//手套攻击卷轴 10%
		    Array(2040810,200,1,1),//手套攻击卷轴 70%
			Array(2040811,200,1,1),//手套攻击卷轴 30%
			Array(2040814,200,1,0),//手套魔力诅咒卷轴70%
			Array(2040815,200,1,0),//手套魔力诅咒卷轴30%
			Array(2040816,200,1,0),//手套魔力卷轴10%
			Array(2040817,200,1,0),//手套魔力卷轴60%
			Array(2040906,500,1,0),//盾牌运气卷轴70%
			Array(2040907,500,1,0),//盾牌运气卷轴 30%
			Array(2040914,200,1,1),//盾牌攻击卷轴60%
			Array(2040915,200,1,1),//盾牌攻击卷轴 10%
			Array(2040916,200,1,1),//盾牌攻击卷轴 70%
			Array(2040917,200,1,1),//盾牌攻击卷轴 30%
			Array(2040919,200,1,0),//盾牌魔力卷轴 60%
			Array(2040920,200,1,0),//盾牌魔力卷轴 10%
		    Array(2040921,200,1,0),//盾牌魔力卷轴 70%
		    Array(2040922,200,1,0),//盾牌魔力卷轴30%
			Array(2040924,500,1,0),//盾牌运气卷轴 60%
			Array(2040925,500,1,0),//盾牌运气卷轴10%
			Array(2040931,500,1,0),//盾牌力量卷轴 60%
			Array(2040932,500,1,0),//盾牌力量卷轴 30%
			Array(2040933,500,1,0),//盾牌力量卷轴10%
			Array(2041013,500,1,0),//披风力量卷轴60%
			Array(2041014,500,1,0),//披风力量卷轴 10%
			Array(2041016,500,1,0),//披风智力卷轴 60%
			Array(2041017,500,1,0),//披风智力卷轴 10%
			Array(2041019,500,1,0),//披风敏捷卷轴 60%
			Array(2041020,500,1,0),//披风敏捷卷轴 10%
			Array(2041022,500,1,0),//披风运气卷轴 60%
			Array(2041023,500,1,0),//披风运气卷轴 10%
			Array(2041034,500,1,0),//披风力量诅咒卷轴 70%
			Array(2041035,500,1,0),//披风力量诅咒卷轴 30%
			Array(2041036,500,1,0),//披风智力诅咒卷轴 70%
			Array(2041037,500,1,0),//披风智力诅咒卷轴 30%
			Array(2041038,500,1,0),//披风敏捷诅咒卷轴70%
			Array(2041039,500,1,0),//披风敏捷诅咒卷轴 30%
			Array(2041040,500,1,0),//披风运气诅咒卷轴 70%
			Array(2041041,500,1,0),//披风运气诅咒卷轴 30%
			Array(2041201,500,1,0),//项链运气卷轴 10%
			Array(2041202,500,1,0),//项链运气卷轴 60%
			Array(2041204,500,1,0),//项链运气卷轴 30%
			Array(2041205,500,1,0),//项链运气卷轴 70%
			Array(2041206,500,1,0),//项链力量卷轴 10%
			Array(2041207,500,1,0),//项链力量卷轴60%
			Array(2041209,500,1,0),//项链力量卷轴 30%
			Array(2041210,500,1,0),//项链力量卷轴 70% 
			Array(2043001,500,1,1),//单手剑攻击卷轴 60%
			Array(2043002,500,1,1),//单手剑攻击卷轴 10%
			Array(2043005,500,1,1),//单手剑攻击卷轴 30%
			Array(2043101,500,1,1),//单手斧攻击卷轴 60%
			Array(2043102,500,1,1),//单手斧攻击卷轴 10%
			Array(2043104,500,1,1),//单手斧攻击卷轴30%
			Array(2043201,500,1,1),//单手钝器攻击卷轴 60%
			Array(2043202,500,1,1),//单手钝器攻击卷轴 10%
			Array(2043204,500,1,1),//单手钝器攻击卷轴 70%
			Array(2043205,500,1,1),//单手钝器攻击卷轴 30%
			Array(2043301,500,1,1),//短剑攻击卷轴 60%
			Array(2043302,500,1,1),//短剑攻击卷轴 10%
			Array(2043304,500,1,1),//短剑攻击卷轴 70%
			Array(2043305,500,1,1),//短剑攻击卷轴 30%
			Array(2043701,500,1,0),//短杖魔力卷轴 60%
			Array(2043702,500,1,0),//短杖魔力卷轴 10%
			Array(2043704,500,1,0),//短杖魔力卷轴 70%
			Array(2043705,500,1,0),//短杖魔力卷轴 30%
			Array(2043801,500,1,0),//长杖魔力卷轴 60%
			Array(2043802,500,1,0),//长杖魔力卷轴 10%
			Array(2043804,500,1,0),//长杖魔力卷轴 70%
			Array(2043805,500,1,0),//长杖魔力卷轴30%
			Array(2044001,500,1,1),//双手剑攻击卷轴 60%
			Array(2044002,500,1,1),//双手剑攻击卷轴 10%
			Array(2044004,500,1,1),//双手剑攻击卷轴 70%
			Array(2044005,500,1,1),//双手剑攻击卷轴 30%
			Array(2044101,500,1,1),//双手斧攻击卷轴 60%
			Array(2044102,500,1,1),//双手斧攻击卷轴 10%
			Array(2044104,500,1,1),//双手斧攻击卷轴 70%
			Array(2044105,500,1,1),//双手斧攻击卷轴30%
			Array(2044201,500,1,1),//双手钝器攻击卷轴 60%
			Array(2044202,500,1,1),//双手钝器攻击卷轴10%
			Array(2044204,500,1,1),//双手钝器攻击卷轴 70%
			Array(2044205,500,1,1),//双手钝器攻击卷轴 30%
			Array(2044301,500,1,1),//枪攻击卷轴60%
			Array(2044302,500,1,1),//枪攻击卷轴 10%
			Array(2044304,500,1,1),//枪攻击卷轴 70%
			Array(2044305,500,1,1),//枪攻击卷轴 30%
			Array(2044311,500,1,0),//枪命中率卷轴70%
			Array(2044312,500,1,0),//枪命中率卷轴60%
			Array(2044401,500,1,1),//矛攻击卷轴 60%
			Array(2044402,500,1,1),//矛攻击卷轴 10%
			Array(2044404,500,1,1),//矛攻击卷轴 70%
			Array(2044405,500,1,1),//矛攻击卷轴 30%
			Array(2044411,500,1,0),//矛命中率卷轴 70%
			Array(2044412,500,1,0),//矛命中率卷轴 60%
			Array(2044413,500,1,0),//矛命中率卷轴30%
			Array(2044501,500,1,1),//弓攻击卷轴 60%
			Array(2044502,500,1,1),//弓攻击卷轴 10%
			Array(2044504,500,1,1),//弓攻击卷轴 70%
			Array(2044505,500,1,1),//弓攻击卷轴 30%
			Array(2044601,500,1,1),//弩攻击卷轴 60%
			Array(2044602,500,1,1),//弩攻击卷轴 10%
			Array(2044604,500,1,1),//弩攻击卷轴 70%
			Array(2044605,500,1,1),//弩攻击卷轴 30%
			Array(2044701,500,1,1),//拳套攻击卷轴 60%
			Array(2044702,500,1,1),//拳套攻击卷轴10%
			Array(2044704,500,1,1),//拳套攻击卷轴 70%
			Array(2044705,500,1,1),//拳套攻击卷轴30%
			Array(2044801,500,1,1),//拳甲攻击卷轴 60%
			Array(2044802,500,1,1),//拳甲攻击卷轴10%
			Array(2044804,500,1,1),//拳甲攻击卷轴 70%
			Array(2044805,500,1,1),//拳甲攻击卷轴 30%
			Array(2044807,500,1,0),//拳甲命中率卷轴 60%
			Array(2044808,500,1,0),//拳甲命中率卷轴 70%
			Array(2044901,500,1,1),//短枪攻击卷轴 60%
			Array(2044902,500,1,1),//短枪攻击卷轴 10%
			Array(2049100,300,1,1),//混沌
			Array(2049000,500,1,1),//白E
			Array(2044904,500,1,1),//短枪攻击卷轴 70%
		//	Array(2044905,500,1,0),//短枪攻击卷轴 30%
			Array(2041040,500,1,1) //披风运气70
);



function start() {
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == 1) {
        status++;
    } else {
        if (status == 0) {
            cm.sendOk("不想使用吗？…我的肚子里有各类#b卷轴#k哦！");
            cm.dispose();
        }
        status--;
    }
    var  jpzs = "";
    for (var ii = 0; ii < itemList.length; ii++) {
    	jpzs += "#v" + itemList[ii][0] + "#";
    }
    if (status == 0) {
		if(cm.getPlayer().getLevel()<10){
			cm.sendOk("您的等级太低，无法使用快乐百宝箱。");
			cm.dispose();
			return;
		}
        if (cm.haveItem(5220000,1)) {
            cm.sendSimple("冒险岛转蛋机中有各类#b卷轴#k噢！使用“#b#t5220000##k”就可以抽奖，否则是不可以使用我的。现在要玩转蛋机么? \r\n#b#L2#试试手气吧#l#k\r\n#b#L4#十连抽#l#k\r\n#b#L6##r20万金币#b购买1张#v5220000##k\r\n#b#L7##r200万金币#b购买11张#v5220000##l#k\r\n\r\n\r\n部分奖励展示:\r\n" + jpzs);
        } else {
        	cm.sendSimple("冒险岛转蛋机中有各类#b卷轴#k噢！使用“#b#t5220000##k”就可以交换。 假如不买转蛋券的话，是不可以使用我的。需要购买吗?\r\n#b#L6##r20万金币#b购买1张#v5220000##k\r\n#b#L7##r200万金币#b购买11张#v5220000##l#k\r\n\r\n\r\n#k部分奖励展示:\r\n" + jpzs +"");
        }
    } else if (selection == 2) {
        var chance = cm.getDoubleFloor(cm.getDoubleRandom() * 500);
        var finalitem = Array();
        for (var i = 0; i < itemList.length; i++) {
            if (itemList[i][1] >= chance) {
                finalitem.push(itemList[i]);
            }
        }
        if (finalitem.length != 0) {
            var item;
            var random = new java.util.Random();
            var finalchance = random.nextInt(finalitem.length);
            var itemId = finalitem[finalchance][0];
            var quantity = finalitem[finalchance][2];
            var notice = finalitem[finalchance][3];
            item = cm.gainGachaponItem(itemId, quantity, "卷轴转蛋机", notice);
            if (item != -1) {
                cm.gainItem(5220000, -1);
                cm.sendOk("你获得了 #b#t" + item + "##k " + quantity + "个。");
                //给1个币
               // cm.gainItem(4000508,1);
            } else {
                cm.sendOk("你确实有#b#t5220000##k吗？如果是，请你确认在背包的装备，消耗，其他窗口中是否有一格以上的空间。");
            }
            cm.safeDispose();
        } else {
            cm.sendOk("今天的运气可真差，什么都没有拿到。\r\n(获得了安慰奖：#v2000005#。)");
            cm.gainItem(5220000, -1);
            // cm.gainItem(4000508, 1);
            cm.setBossRankCount("快乐百宝箱抽奖",1);
				cm.setBossRankCount("快乐百宝箱抽奖积分",1);
            cm.safeDispose();
        }
    } else if  (selection == 4) {
		var itemids = [];
		if (!cm.haveItem(5220000,10)){
			cm.sendOk("你的 #b#t5220000# #k不够 #r10 #k张，无法抽奖。");
			cm.dispose();
			return;
		}
		/*if (cm.getInventory(1).isFull(9)){
			cm.sendOk("请保证背包#b装备栏#k至少有 #r10 #k个位置");
			cm.dispose();
			return;
		}*/
		if (cm.getInventory(2).isFull(9)){
			cm.sendOk("请保证背包#b消耗栏#k至少有 #r10 #k个位置");
			cm.dispose();
			return;
		}
		/*if (cm.getInventory(3).isFull(9)){
			cm.sendOk("请保证背包#b设置栏#k至少有 #r10 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getInventory(4).isFull(9)){
			cm.sendOk("请保证背包#b其他栏#k至少有 #r10 #k个位置");
			cm.dispose();
			return;
		}*/
		for (var j = 0; j < 10;j ++) {
			var chance = cm.getDoubleFloor(cm.getDoubleRandom() * 500);
			var finalitem = Array();
			for (var i = 0; i < itemList.length; i++) {
				if (itemList[i][1] >= chance) {
                finalitem.push(itemList[i]);
				}
			}
			if (finalitem.length != 0) {
				var item;
				var random = new java.util.Random();
				var finalchance = random.nextInt(finalitem.length);
				var itemId = finalitem[finalchance][0];
				var quantity = finalitem[finalchance][2];
				var notice = finalitem[finalchance][3];
				item = cm.gainGachaponItem(itemId, quantity, "卷轴转蛋机", notice);
				if (item != -1) {
					cm.gainItem(5220000, -1);
					itemids.push(itemId);
					//给1个纪念币
					//cm.gainItem(4000000,1);
				} else {
					cm.sendOk("你确实有#b#t5220000##k吗？如果是，请你确认在背包的装备，消耗，其他窗口中是否有一格以上的空间。");
				}
				cm.safeDispose();
			} else {
				cm.sendOk("今天的运气可真差，什么都没有拿到。\r\n(获得了安慰奖：#v2000005#。)");
				cm.gainItem(5220000, -1);
				//cm.gainItem(4000000, 1);
				cm.safeDispose();
			}
        }
		var idtext = "以下是你抽到的物品:\r\n";
		for (var c = 0;c<itemids.length; c++) {
			idtext += "#v" + itemids[c] + "##z" + itemids[c] + "#\r\n";
		}
		cm.sendSimple(idtext);
		cm.safeDispose;
	} else if  (selection == 6) {
		if (cm.getInventory(1).isFull()){
			cm.sendOk("请保证背包#b装备栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getInventory(2).isFull()){
			cm.sendOk("请保证背包#b消耗栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getInventory(3).isFull()){
			cm.sendOk("请保证背包#b设置栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getInventory(4).isFull()){
			cm.sendOk("请保证背包#b其他栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getMeso() < 200000){
			cm.sendOk("购买#v5220000#需要 #b金币 300000 #k您的金币不足");
			cm.dispose();
			return;
		}
		cm.gainMeso(-200000);
		cm.gainItem(5220000,1);
		cm.dispose();
	} else if  (selection == 7) {
		if (cm.getInventory(1).isFull()){
			cm.sendOk("请保证背包#b装备栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getInventory(2).isFull()){
			cm.sendOk("请保证背包#b消耗栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getInventory(3).isFull()){
			cm.sendOk("请保证背包#b设置栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getInventory(4).isFull()){
			cm.sendOk("请保证背包#b其他栏#k至少有 #r1 #k个位置");
			cm.dispose();
			return;
		}
		if (cm.getMeso() < 2000000){
			cm.sendOk("购买#v5220000#需要 #b金币 3000000 #k您的金币不足");
			cm.dispose();
			return;
		}
		cm.gainMeso(-2000000);
		cm.gainItem(5220000,11);
		cm.dispose();
	}
}
